// Demo_PTB2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "math.h"
#include "conio.h"
using namespace std;

void nhap (float &, float &, float &);
float delta(float , float, float );
void Nghiem_ac(float, float, float, float &, float &);

void main()
{
	float a,b,c;
	float x1, x2;
	nhap(a,b,c);
    if(delta(a,b,c) < 0)
	{
		cout << "Vo nghiem"<<  endl;
		return;
	}
	if(delta(a,b,c) == 0)
	{
		Nghiem_ac(a,b,c,x1,x2); 
		cout << "Co nghiem kep x = " << x1 <<  endl;
		return;
	}
	Nghiem_ac(a,b,c,x1,x2); 
		cout << "Co nghiem kep x1 = " << x1 << " va x2 = " << x2<<  endl;
	getch();
}

void nhap(float &a, float &b, float &c)
{
	cout<<"Nhap a: ";
	cin>> a;
	cout<<"Nhap b: ";
	cin>> b;
	cout<<"Nhap c: ";
	cin>> c;
}

void Nghiem_ac(float a, float b, float c, float &x1, float &x2)
{
	float dt = delta(a,b,c);
	if(dt < 0)
		return;
	if(dt==0)
	{
	 x1 = x2 = (-b/(2*a));
	 return;
	}
	x1 = (-b + sqrt(dt))/(2*a);
	x2 = (-b + sqrt(dt))/(2*a);
	return;
}

float delta(float a, float b, float c)
{
	return (b*b) - 4*a*c;
}